﻿using CodeLibrary.Consts;

namespace CodeLibrary.Extensions.Common
{
    internal static class NumberArticulator
    {

        public static string ConvertNumberToWord(long numberVal)
        {
            string wordValue = "";

            if (numberVal == 0)
            {
                return NumberFormatter.FormatUnit(NumberUnit.Zero);
            }

            if (numberVal < 0)
            {
                wordValue = NumberFormatter.FormatSign(NumberSign.Negative);
                numberVal = -numberVal;
            }

            long[] partStack = new long[] { 0, 0, 0, 0 };
            int partNdx = 0;

            while (numberVal > 0)
            {
                partStack[partNdx++] = numberVal % 1000;
                numberVal /= 1000;
            }

            for (int i = 3; i >= 0; i--)
            {
                long part = partStack[i];

                //if (part >= 100)
                //{
                //    wordValue += NumberConst.ones[part / 100 - 1] + NumberFormatter.FormatUnit(NumberUnit.Hundred;
                //    part %= 100;
                //}

                //if (part >= 20)
                //{
                //    if ((part % 10) != 0) wordValue += NumberConst.tens[part / 10 - 2] +
                //       " " + NumberConst.ones[part % 10 - 1] + " ";
                //    else wordValue += NumberConst.tens[part / 10 - 2] + " ";
                //}
                //else if (part > 0) wordValue += NumberConst.ones[part - 1] + " ";

                //if (part != 0 && i > 0) wordValue += NumberConst.powers[i - 1];
            }

            return wordValue.Trim();
        }
    }
}